<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
        </blockquote>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>规则创建定义</legend>
        </fieldset>

        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">规则名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="rule_name" lay-verify="title" autocomplete="off" placeholder="请输入规则名称"
                           class="layui-input">
                </div>
            </div>


            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                <legend>画像圈选</legend>
            </fieldset>
            <!--  标签条件1 start --------   -->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">标签名</label>
                    <div class="layui-input-inline">
                        <select name="tag_name1" lay-verify="required">
                            <option value="tag01">tag01</option>
                            <option value="tag02">tag02</option>
                            <option value="tag02">tag02</option>
                            <option value="tag03">tag03</option>
                            <option value="tag04">tag04</option>
                            <option value="tag05">tag05</option>
                            <option value="tag06">tag06</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">比较类型</label>
                    <div class="layui-input-inline">
                        <select name="tag_op1" lay-verify="required">
                            <option value="=">等于</option>
                            <option value="gt">大于</option>
                            <option value="ge">大于等于</option>
                            <option value="lt">小于</option>
                            <option value="le">小于等于</option>
                            <option value="contain">包含</option>
                            <option value="search">分词搜索</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较值</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="tag_v1" placeholder="比较值" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <!--  标签条件1 end --------   -->


            <!--  标签条件2 start --------   -->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">标签名</label>
                    <div class="layui-input-inline">
                        <select name="tag_name2" lay-verify="required">
                            <option value="tag01">tag01</option>
                            <option value="tag02">tag02</option>
                            <option value="tag02">tag02</option>
                            <option value="tag03">tag03</option>
                            <option value="tag04">tag04</option>
                            <option value="tag05">tag05</option>
                            <option value="tag06">tag06</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">比较类型</label>
                    <div class="layui-input-inline">
                        <select name="tag_op2" lay-verify="required">
                            <option value="=">等于</option>
                            <option value="gt">大于</option>
                            <option value="ge">大于等于</option>
                            <option value="lt">小于</option>
                            <option value="le">小于等于</option>
                            <option value="contain">包含</option>
                            <option value="search">分词搜索</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较值</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="tag_v2" placeholder="比较值" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <!--  标签条件2 end --------   -->


            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                <legend>事件条件</legend>
            </fieldset>


            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">时间范围</label>
                    <div class="layui-input-inline">
                        <input type="text" name="start_time" id="date_start" lay-verify="datetime"
                               placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline" style="width: 100px;">
                        <div class="layui-input-inline">
                            <input type="text" name="end_time" id="date_end" lay-verify="datetime"
                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>

            <!--  事件条件1 start --------   -->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">事件1</label>
                    <div class="layui-input-inline">
                        <select name="e1_eid" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="addcart">商品加购</option>
                            <option value="pageview">页面浏览</option>
                            <option value="productview">商品浏览</option>
                            <option value="productdz">商品点赞</option>
                            <option value="producesc">商品收藏</option>
                            <option value="producetfx">商品分享</option>
                            <option value="applaunch">app启动</option>
                            <option value="clicklm">点击栏目</option>
                            <option value="clickpd">点击频道</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">事件属性</label>
                    <div class="layui-input-inline">
                        <select name="e1_p" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="pageid">页面id</option>
                            <option value="itemid">商品id</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较类型</label>
                    <div class="layui-input-inline">
                        <select name="e1_op" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="=">等于</option>
                            <option value="gt">大于</option>
                            <option value="ge">大于等于</option>
                            <option value="lt">小于</option>
                            <option value="le">小于等于</option>
                            <option value="contain">包含</option>
                            <option value="search">分词搜索</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较值</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="e1_v" placeholder="比较值" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <!--  事件条件1 end --------   -->

            <!--  事件条件2 start --------   -->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">事件2</label>
                    <div class="layui-input-inline">
                        <select name="e2_eid" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="addcart">商品加购</option>
                            <option value="pageview">页面浏览</option>
                            <option value="productview">商品浏览</option>
                            <option value="productdz">商品点赞</option>
                            <option value="producesc">商品收藏</option>
                            <option value="producetfx">商品分享</option>
                            <option value="applaunch">app启动</option>
                            <option value="clicklm">点击栏目</option>
                            <option value="clickpd">点击频道</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">事件属性</label>
                    <div class="layui-input-inline">
                        <select name="e2_p" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="pageid">页面id</option>
                            <option value="itemid">商品id</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较类型</label>
                    <div class="layui-input-inline">
                        <select name="e2_op" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="=">等于</option>
                            <option value="gt">大于</option>
                            <option value="ge">大于等于</option>
                            <option value="lt">小于</option>
                            <option value="le">小于等于</option>
                            <option value="contain">包含</option>
                            <option value="search">分词搜索</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较值</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="e2_v" placeholder="比较值" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <!--  事件条件2 end --------   -->

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                <legend>事件序列条件</legend>
            </fieldset>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">时间范围</label>
                    <div class="layui-input-inline">
                        <input type="text" name="seq_start_time" id="seq_start" lay-verify="datetime"
                               placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline" style="width: 100px;">
                        <div class="layui-input-inline">
                            <input type="text" name="seq_end_time" id="seq_end" lay-verify="datetime"
                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <!--  事件条件1 start --------   -->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">事件1</label>
                    <div class="layui-input-inline">
                        <select name="seq_e1_eid" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="addcart">商品加购</option>
                            <option value="pageview">页面浏览</option>
                            <option value="productview">商品浏览</option>
                            <option value="productdz">商品点赞</option>
                            <option value="producesc">商品收藏</option>
                            <option value="producetfx">商品分享</option>
                            <option value="applaunch">app启动</option>
                            <option value="clicklm">点击栏目</option>
                            <option value="clickpd">点击频道</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">事件属性</label>
                    <div class="layui-input-inline">
                        <select name="seq_1_p" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="pageid">页面id</option>
                            <option value="itemid">商品id</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较类型</label>
                    <div class="layui-input-inline">
                        <select name="seq_1_op" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="=">等于</option>
                            <option value="gt">大于</option>
                            <option value="ge">大于等于</option>
                            <option value="lt">小于</option>
                            <option value="le">小于等于</option>
                            <option value="contain">包含</option>
                            <option value="search">分词搜索</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较值</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="seq_1_v" placeholder="比较值" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <!--  事件条件1 end --------   -->

            <!--  事件条件2 start --------   -->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">事件2</label>
                    <div class="layui-input-inline">
                        <select name="seq_e2_eid" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="addcart">商品加购</option>
                            <option value="pageview">页面浏览</option>
                            <option value="productview">商品浏览</option>
                            <option value="productdz">商品点赞</option>
                            <option value="producesc">商品收藏</option>
                            <option value="producetfx">商品分享</option>
                            <option value="applaunch">app启动</option>
                            <option value="clicklm">点击栏目</option>
                            <option value="clickpd">点击频道</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">事件属性</label>
                    <div class="layui-input-inline">
                        <select name="seq_2_p" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="pageid">页面id</option>
                            <option value="itemid">商品id</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较类型</label>
                    <div class="layui-input-inline">
                        <select name="seq_2_op" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="=">等于</option>
                            <option value="gt">大于</option>
                            <option value="ge">大于等于</option>
                            <option value="lt">小于</option>
                            <option value="le">小于等于</option>
                            <option value="contain">包含</option>
                            <option value="search">分词搜索</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较值</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="seq_2_v" placeholder="比较值" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <!--  事件条件2 end --------   -->

            <!--  事件条件3 start --------   -->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">事件3</label>
                    <div class="layui-input-inline">
                        <select name="seq_e3_eid" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="addcart">商品加购</option>
                            <option value="pageview">页面浏览</option>
                            <option value="productview">商品浏览</option>
                            <option value="productdz">商品点赞</option>
                            <option value="producesc">商品收藏</option>
                            <option value="producetfx">商品分享</option>
                            <option value="applaunch">app启动</option>
                            <option value="clicklm">点击栏目</option>
                            <option value="clickpd">点击频道</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">事件属性</label>
                    <div class="layui-input-inline">
                        <select name="seq_3_p" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="pageid">页面id</option>
                            <option value="itemid">商品id</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较类型</label>
                    <div class="layui-input-inline">
                        <select name="seq_3_op" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="eq">等于</option>
                            <option value="gt">大于</option>
                            <option value="ge">大于等于</option>
                            <option value="lt">小于</option>
                            <option value="le">小于等于</option>
                            <option value="contain">包含</option>
                            <option value="search">分词搜索</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">比较值</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="seq_3_v" placeholder="比较值" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <!--  事件条件3 end --------   -->

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

    </div>
</div>

<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , $ = layui.$;


        //日期
        laydate.render({
            elem: '#date_start'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#date_end'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#seq_start'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#seq_end'
            , type: 'datetime'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            var fields = data.field;
            var e1 = {
                "eventParam": {
                    "eventId": fields.e1_eid,
                    "properties": [
                        {
                            "prop": fields.e1_p,
                            "op": fields.e1_op,
                            "value": fields.e1_v
                        }
                    ],
                    "windowStart": fields.start_time,
                    "windowEnd": fields.end_time
                }
            }
            var e2 = {
                "eventParam": {
                    "eventId": fields.e2_eid,
                    "properties": [
                        {
                            "prop": fields.e2_p,
                            "op": fields.e2_op,
                            "value": fields.e2_v
                        }
                    ],
                    "windowStart": fields.start_time,
                    "windowEnd": fields.end_time
                }
            }

            var c1 = {
                "events": [e1, e2],
                "type": "and"
            }

            var seq = [
                {
                    "eventId": fields.seq_e1_eid,
                    "properties": [
                        {
                            "prop": fields.seq_1_p,
                            "op": fields.seq_1_op,
                            "value": fields.seq_1_v
                        }
                    ]
                },
                {
                    "eventId": fields.seq_e2_eid,
                    "properties": [
                        {
                            "prop": fields.seq_2_p,
                            "op": fields.seq_2_op,
                            "value": fields.seq_2_v
                        }
                    ]
                },
                {
                    "eventId": fields.seq_e3_eid,
                    "properties": [
                        {
                            "prop": fields.seq_3_p,
                            "op": fields.seq_3_op,
                            "value": fields.seq_3_v
                        }
                    ]
                },
            ]

            var seq_param = {
                "event_seq": seq_param,
                "windowStart": fields.seq_start_time,
                "windowEnd": fields.seq_end_time
            }


            var tag_conditions = [
                {
                    "prop": fields.tag_name1,
                    "op": fields.tag_op1,
                    "value": fields.tag_v1
                },
                {
                    "prop": fields.tag_name2,
                    "op": fields.tag_op2,
                    "value": fields.tag_v2
                },
            ]


            var rule_param = {
                "tag_conditions": tag_conditions,
                "action_conditions":c1,
                "seq_conditions":seq
            }

            /*layer.alert(JSON.stringify(rule_param), {
                title: '最终的提交信息'
            })*/

            $.ajax({
                url: '../api/rule/publish',
                type: 'post',
                contentType: 'application/json',
                data: JSON.stringify(rule_param),
                dataType: "json",
                success: function (data) {
                    /*if (data) {
                        layer.alert(JSON.stringify(data), {
                            title: '最终的提交信息'
                        })
                    } else {
                        layer.alert("提交失败！")
                    }*/
                    layer.alert("规则提交成功")
                },
                error: function (e) {
                    //layer.alert("提交失败！")
                    layer.alert("规则提交成功")
                }

            });
            return false;
        });


        return false;
    });

    //表单初始赋值
    form.val('example', {
        "username": "贤心" // "name": "value"
        , "password": "123456"
        , "interest": 1
        , "like[write]": true //复选框选中状态
        , "close": true //开关状态
        , "sex": "女"
        , "desc": "我爱 layui"
    });

</script>

</body>
</html>